package luafrontend.values;

import luafrontend.exceptions.ConversionException;

public class LuaString extends LuaValue {
	private final String str;
	
	public LuaString(String str) {
		this.str = str;
	}
	
	public LuaNumber asNumber() throws ConversionException {
		try {
			return new LuaNumber(Double.parseDouble(str));
		}
		catch (NumberFormatException e) {
		}
		
		return super.asNumber();
	}
	
	public LuaString asString() throws ConversionException {
		return this;
	}
	
	public String getString() {
		return str;
	}
	
	public String toString() {
		return "'" + str + "'";
	}

	@Override
	public int hashCode() {
		return str.hashCode();
	}
	
	@Override
	public boolean equals(Object other) {
		return other instanceof LuaString && str.equals(((LuaString) other).str);
	}
}
